﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Game.Types;

namespace GameEditor2.Toolbox
{
    /// <summary>
    /// Interaction logic for ObjectItemControl.xaml
    /// </summary>
    public partial class VehicleItemControl : UserControl
    {
        MapItemType _MapItemType;
        
        public VehicleItemControl()
        {
            InitializeComponent();
            
            SelectedVehicleType.Selected += delegate 
            {
                UpdatePressedState();
            };
        }
        
        public Brush ToolColor
        {
            get { return this.button1.Background; }
            set { this.button1.Background=value; }
        }
        
        public MapItemType MapItemType
        {
            get { return _MapItemType; }
            set { _MapItemType = value; DisplayType(); }
        }
        
        void DisplayType()
        {
            if (_MapItemType != null)
            {
                if (_MapItemType.Picture != null)
                {
                    BitmapImage image = new BitmapImage();
                    image.BeginInit();
                    image.StreamSource = _MapItemType.Picture.Stream;
                    image.EndInit();
                    buttonImage.Source = image;
                }
            }
            else
            {
            }
        }
        
        void Button_Click(object sender, RoutedEventArgs e)
        {
            SelectedVehicleType.VehicleType = _MapItemType as VehicleType;
        }
        
        void UpdatePressedState()
        {
            if (SelectedVehicleType.VehicleType == this._MapItemType)
            {
                this.button1.Background=SystemColors.HighlightBrush;
            }
            else
            {
                this.button1.Background=SystemColors.ControlLightBrush;
            }
        }
        
    }
}